const {
  CloudFunction
} = require('../Class/Cloud.js')

class get_teacher_info {
  // 这里放数据
  constructor() {

  }

  // 这个方法是用来获取老师数据的
  GetTeacherInfo() {
    const TeacherInfo = new CloudFunction('GetTeacher_data');
    const result = TeacherInfo.callAsync().then(res => {
      const hanyuyan = res.result[0].data
      const xinwen = res.result[1].data
      const wangxin = res.result[2].data
      const total_teacherInfo = [...hanyuyan,...xinwen,...wangxin]
      return {
        hanyuyan,
        xinwen,
        wangxin,
        total_teacherInfo
      }
    }).catch(err => {
      console.log('数据请求失败', err)
    })
    return result
  }

  // 这个方法封装的是vantab需要返回的数据
  GetUserChoice(id, hanyuyan, xinwen, wangxin) {
    switch (id) {
      case 0:
        return hanyuyan;
      case 1:
        return xinwen;
      case 2:
        return wangxin;
    }
  }

  // 这个方法是跳转到老师详情页面的
  GoTeacherInfo(tabid, teacherid) {
    const TeacherInfo = new CloudFunction('GetTeacher_data');
    const result = TeacherInfo.callAsync().then(res=>{
      const hanyuyan = res.result[0].data
      const xinwen = res.result[1].data
      const wangxin = res.result[2].data
      switch(tabid){
        case 0:
          return hanyuyan[teacherid]
        case 1:
          return xinwen[teacherid]
        case 2:
          return wangxin[teacherid]
      }
    }).catch(err=>{
      console.log('获取数据失败：',err)
    })
    return result
  }

}

// 这里暴露方法名
module.exports = {
  get_teacher_info
}